#ifndef TEXTRENDERER_H
#define TEXTRENDERER_H

#include <plib/fnt.h>
#include "camera.h"
#include "Singleton.h"

class TextRenderer : public Singleton<TextRenderer>
{
public:
    enum Alignment { Top, Left, Center, Right, Bottom };
    
    TextRenderer();
    ~TextRenderer();
    
    void setup();
    
    void begin();
    void end();
    
    void drawWithCamera(const char* str, Camera& camera, float height = 100000.0f, float width = 100000.0f);
	
	void setOutputAlignment(Alignment horizontal = Left, Alignment vertical = Center) { outputHorizontalAlignment = horizontal, outputVerticalAlignment = vertical; }
	void setInputAlignment(Alignment horizontal = Left, Alignment vertical = Center) { inputHorizontalAlignment = horizontal, inputVerticalAlignment = vertical; }
	
	float getMaxPixelHeight() const { return maxPixelHeight; };
	void setMaxPixelHeight(float maxPixelHeight) { this->maxPixelHeight = maxPixelHeight; }
	
	BoundingBox getWorldBoundingBoxWithCamera(const char* str, Camera& camera, float height = 100000.0f, float width = 100000.0f);

protected:
    float fitString(char* out, const char* str, float height, float width);
    
protected:
    fntRenderer *textRenderer;
    
    float bbLeft, bbRight, bbTop, bbBottom, bbWidth, bbHeight, meanNormCharWidth;
    
    float maxPixelHeight;
	
	Alignment outputVerticalAlignment, outputHorizontalAlignment;
	Alignment inputVerticalAlignment, inputHorizontalAlignment;
    
private:
    char buffer[1024];
};

#endif // TEXTRENDERER_H
